home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 83 < prev    next >
Internet Message Format  |  1996-08-06  |  4KB

  1. Path: tko.dec.com!diamond
  2. From: diamond@tko.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c,comp.arch.arithmetic,sci.math.num-analysis
  4. Subject: Re: Why is <float.h>? [was Re: sizeof(1L) in preprocesor ...]
  5. Date: 12 Jan 1996 02:02:51 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4d4fgb$22d@usenet.pa.dec.com>
  8. References: <sc3f9vb6gk.fsf@lns101.lns.cornell.edu> <4ctk66$57j@lyra.csx.cam.ac.uk> <KANZE.96Jan9135752@slsvewt.lts.sel.alcatel.de> <4ctpkv$82v@lyra.csx.cam.ac.uk> <4d1hh7$kd@lyra.csx.cam.ac.uk>
  9. Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tko.dec.com
  11.  
  12. In article <4d1hh7$kd@lyra.csx.cam.ac.uk>, nmm1@cus.cam.ac.uk (Nick Maclaren) writes:
  13. >Numerical analysts use values of the sort that are found in <float.h>
  14. >for many purposes, including:
  15. >    1) Switching to alternate algorithms for special functions.
  16. >    2) Avoiding overflow, underflow and rounding error.
  17. >    3) Selecting appropriate precisions for conversion on I/O.
  18. >    4) Varying the algorithm in the rare cases where it matters.
  19. >Now, (1) needs the values to be preprocessor constants for efficiency.
  20. >Remember that such people are the very people who write the functions
  21. >called via <math.h>, and we like to be able to write code that compiles
  22. >automatically and correctly even on machines that we have never heard
  23. >of!  But to do this efficiently, we have to define our OWN <float.h>,
  24. >which isn't portable!
  25.  
  26. No, for (1), you do not need to define your own <float.h>.  You need
  27. to address two categories:
  28.  
  29. (A)  Implementations where definitions in <float.h> are preprocessor
  30. constants.  You can write one version of your code using #if directives
  31. as necessary, presuming that these are preprocessor constants, and your
  32. code will work under all such implementations.
  33.  
  34. (B)  Implementations where definitions in <float.h> are not preprocessor
  35. constants.  Some of these implementations would be written for and by the
  36. PC crowd that your article mentioned, in which the underlying features
  37. really are not constant and can be varied at run time.  Others of these
  38. implementations would be perverse and not really allow varying at run
  39. time, but you do not have to worry about that, you can just assume that
  40. varying is allowed and you have no problem.  You can write one version of
  41. your code using if statements as necessary, without presuming that these
  42. are preprocessor constants, and your code will work under all implementations.
  43.  
  44. You might want to provide just one version with additional #if directives
  45. to choose between version (A) for efficiency and (B) for reliability.
  46.  
  47. And to make this relevant to the C standard, someone who is allowed to
  48. propose new features should propose a preprocessor operator "const",
  49. in the same form as the preprocessor operator "defined", which returns
  50. a 1 if the preprocessor can evaluate the argument as a constant.
  51. This even avoids stealing a keyword from the language, since there
  52. isn't much else a program could do with an identifier named "const".
  53. (Of course this doesn't indicate whether later phases of translation
  54. can evaluate the argument as a constant, but some preprocessors cannot
  55. know whether later phases are capable of that anyway.)
  56.  
  57. >For categories (2)-(4), efficiency is not crucial.
  58.  
  59. In another thread going on now at your friendly local news server, some
  60. participants argue that for category (2), efficiency is just as crucial.
  61. --
  62.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  63. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  64. license, so I can drive in any lane I want, and no innocent victim gets to call
  65. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  66.